/**
 * 总路由控制文件
 *
 * @author bian
 * @createDate 2016.5.20
 * @modifyDate 2016.8.20 添加错误处理中间件
 * @modifyDate 2016.8.22 重构身份认证中间件机制
 */
// library module
var Router = require("koa-router");

// my module
var utilx = require("../lib/utilx");
var debug = require("../instances/debug");
var logger = require("../instances/log");
var xmlParse = require("../lib/xml");

const router = new Router({
    prefix: "/wechat"
});

/**
 * 错误处理中间件
 */
router.use(function *(next) {
    var ctx = this;
    try{
        yield next;
    }catch(err){
        debug(err);
        logger.error(err);
        ctx.status = 200;
        ctx.body = "";
    }
});

router.get("/",function *(){
    var ctx = this;
    ctx.status = 200;
    ctx.response.set("Content-Type","text/plain;charset=utf-8");
    ctx.body = "反向代理设置";
});

utilx.autoImport(__dirname,(tmpPath) => {   // 自动引入
    require(tmpPath)(router);
});

const routes = router.routes();

module.exports = routes;
